Skip to content

[PR] fix: over-window requests are no longer rejected by local estimation — after folding, always forward; let upstream decid | fix: 超窗请求不再被本地估算拒发——折叠后一律转发,超不超窗让上游自己说 (#7537) - #7548

Merged
ranxianglei merged 6 commits into
masterfrom
fix/preflight-413-passthrough
Nov 23, 2026

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

超窗请求不再被本地估算拒发:折叠后一律转发,超不超窗让上游自己说

1. 这是啥问题?

bili 在转发前用「本地估算 token 数 × 本地记录的窗口值」判断请求会不会超窗。
两者都是猜的:窗口值经常是错的(fallback 窗口、#7205),估算也常偏。
这个乘积只要偏大,bili 就直接回 413「NOT forwarded」——请求根本没发出去,
而实际上很多这种请求上游是能正常处理的。这一家族的问题全部源于此:
#7167、#7382、#2490、#2847、#736、#737、#4079(详见 #7537 的讨论)。

2. 根本原因

一个「本地估算 × 本地窗口」的确定性拒发门。窗口值本身没有上游背书时,
任何基于它的拒发都是在替上游做决定——而且经常做错。

3. 修了什么(owner 2026-11-22 拍板,写入 AGENTS.md KDD #19 / design-decisions #20)

原则:本地估算一律不得拒发;折叠照做,然后转发;超不超窗以上游的真实报错为准。

4. 能否合并

  • 单文件跑全绿(18 个相关文件、41 个用例):issue7537-preflight-passthrough 3/3、
    issue2490 9/9、issue2847 1/1、issue4079 4/4、preflight-fail-fast 8/8、
    issue1841 3/3、issue3645 4/4、issue4185 5/5、issue496 1/1、
    issue3918 2/2、issue5000 3/3、issue5191 1/1、fix-arm-headroom-clamp 3/3、
    preflight-nonstream-400-probe 2/2、issue3004 7/7;tsc --noEmit 干净。
  • 行为变化是 owner 拍板的策略变更,不是意外回归:唯一多付的代价是
    「本来会成功的超大请求」不再被本地拦截(这正是目的),以及
    「注定失败的请求」真实打到上游一次(换来上游的权威裁决 + 回环保护)。
  • 建议合并顺序:本 PR 合并后关闭 [PR] fix: 413 seesaw — fail fast on irreducible tool surface, fold a byte-doomed payload once before judging #7507(它加的两道门在新原则下不需要存在)。

5. URL

6. 影响面

所有走 preflight 的超窗路径(Anthropic/OpenAI/Responses 三条线共用
preflightCompressIfNeeded)+ egress fuse 两道尺寸门 + 上游错误注解
(header + 日志;上游 body 一律逐字节透传)。

7. 测试

见 §4。新增 tests/issue7537-preflight-passthrough.test.ts 钉三件事:
① 折叠后仍超窗(无证明墙)→ 转发,上游 413 透传 + x-bili-retryable:false
header(body 逐字节);② 测量超窗但上游接受 → 现在能送达(旧:本地 413 杀死);
③ 消息数门仍是本地拒发。另:#1841 拆成 A(有证明墙 → 证据 413 保留)+
A2(无墙 → 转发);#2391 eager/loaded 工具溢出改为转发;#3900/#987/#496/
#767/#857/#1195 等既有钉全部复绿(见 §4 清单)。

8. 风险

…rd, and let the upstream's own verdict be authoritative (#7537)

Owner ruling 2026-11-22 (issue #7537, KDD #19/#20): every LOCAL estimate-
based 413 refusal is a product of bili's local guess multiplied by a window
value that is itself often wrong (fallback windows #7205). Their product
silently killed requests that would have succeeded (the #7167/#7382/#2490/
#2847/#2847/#736/#737/#4079 family).

- server.ts: the four local size-413 sites (probe doom gate, #1839 measured
  gate, post-fold measured/doom-bytes gates, deterministic-exhaustion
  mapping) now FORWARD with the local measurement logged as evidence.
  Relay-side refusals keep their status: summary relay down -> 502, relay
  429 -> 503. The BILI_MAX_MESSAGES count gate and the 5GiB byte cap are
  exact resource guards and stay.
- relay.ts: the egress window fuse's two size gates log a profile and
  forward; a NEW upstream size-verdict annotation (413 / size-keyword 400)
  logs bili's own measurement, marks the response x-bili-retryable: false
  and merges a bili_evidence block into JSON error bodies so status-driven
  hosts do not retry-loop an unchanged body.
- server.ts: NEW evidence-backed loop guard — an outbound body that already
  drew an upstream size verdict (SHA-1 scoped, 10-min TTL) is refused
  locally as a byte-identical resend (#496 family); changed bodies and the
  identity fast path re-forward freely.
- The window-shrink note now rides the forward warns (the 413 fail-fast it
  decorated is gone); the duplication profile moved onto the over-window
  forward.
- AGENTS.md KDD #19 + reference/design-decisions.md #20 record the ruling.
- Tests: NEW tests/issue7537-preflight-passthrough.test.ts (3); re-pinned
  issue1841/2490/2847/3645/4079/4185/preflight-fail-fast to passthrough
  semantics; tests/issue3846-local-refusal-evidence.test.ts deleted (the
  local refusal it pinned no longer exists — the loop guard replaces it).

Supersedes PR #7507 (whose two new gates no longer need to exist under
this ruling). Refs #7537 #7507 #7167 #7382 #2490 #2847 #736 #737 #4079
#4543 #1841 #3645 #496 #3846 #3461 #5000
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/preflight-413-passthrough (6607dfc)

Latest build — install this exact version

npm install -g billion-context@0.0.11522-pr.7548.5f69c14

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
6607dfc billion-context@0.0.11522-pr.7548.5f69c14 build
3fe69f5 billion-context@0.0.11484-pr.7548.7118453 build
033c679 billion-context@0.0.11476-pr.7548.58f4cda build
2d65b3c billion-context@0.0.11467-pr.7548.6721335 build
6cf7d60 billion-context@0.0.11457-pr.7548.2618202 build
7b3a171 billion-context@0.0.11445-pr.7548.11c312b build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7548.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: 超窗请求不再被本地估算拒发——折叠后一律转发,超不超窗让上游自己说 (#7537) [PR] fix: over-window requests are no longer rejected by local estimation — after folding, always forward; let upstream decid | fix: 超窗请求不再被本地估算拒发——折叠后一律转发,超不超窗让上游自己说 (#7537) Nov 22, 2026
ranxianglei and others added 2 commits November 23, 2026 00:06
…ate-refusal behavior

The #7537 PR (owner ruling 2026-11-22: no local estimate-based size refusal) removed every estimate 413 and updated 7 preflight test files plus deleted issue3846, but missed tests/fix-identity-fast-path-preflight.test.ts — its 3 tests still pinned the old 413-veto, so the full suite went red.

Apply the PR's own rewrite pattern (issue2847/issue4185): the 413-veto assertions become forward/upstream-decides assertions; the log-line assertion moves from 'identity fast path' to the #7537 no-estimate-refusal forward line. A2 (fresh evidence) keeps the 200-forward behavior; B (stale-origin) and B2 (stale-model) drop the 413 veto and assert the payload is forwarded, the upstream decides. Verified locally: file 5/5 green, typecheck clean.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI fix for PR #7548 (e-work mirror #7550) — attempt 1/6

What I did this run:

  1. Re-verified the live check state (per "RE-VERIFY FIRST"):

    • unused-exports: already fixed by a previous run (commit 6cf7d60a9da "chore: drop the export from upstreamSizeVerdictCovers") — now green.
    • Full test suite: RED — 56 check-runs, 11 failures (all test (os, node, shard) shards), 3 failing tests, all in tests/fix-identity-fast-path-preflight.test.ts.
  2. Root-caused the 3 failing tests: PR [PR] fix: over-window requests are no longer rejected by local estimation — after folding, always forward; let upstream decid | fix: 超窗请求不再被本地估算拒发——折叠后一律转发,超不超窗让上游自己说 (#7537) #7548 (closes Preflight: don't reject based on local estimation — after folding, forward unconditionally; if it exceeds the window, le | preflight 不用本地估算拒发:折叠后一律转发,超窗让上游自己说(413 拒发家族总根因) #7537) implements the owner ruling 2026-11-22 (no local estimate-based size refusal — after folding, always forward; the upstream's own verdict is authoritative). The PR updated 7 preflight test files and deleted issue3846, but missed tests/fix-identity-fast-path-preflight.test.ts — its 3 tests still pinned the removed 413-veto behavior. This was a mechanical oversight, not a design gap.

  3. Fixed the 3 tests (mechanical catch-up, following the PR author's own pattern from issue2847/issue4185 — 413-veto assertions → forward/upstream-decides):

  4. Verified locally: the test file is 5/5 green; npm run typecheck is clean (exit 0). No production code touched — test assertions only.

  5. Pushed the final head 2d65b3cb25f (unmarked → full CI pass). The remote branch was unchanged (6cf7d60a9da), so it was a clean fast-forward.

Current CI status: the mirror cache is stale (fetched_at 2026-11-22T16:14:49Z, before my push ~17:25 UTC); the 30 checks shown are from the previous head. The CI for the new head 2d65b3cb25f is running — I cannot assert green yet.


八问

  1. 是什么问题: CI 红了——unused-exports 检查失败(前一轮已修好),以及完整测试套件有 3 个测试失败(都在 tests/fix-identity-fast-path-preflight.test.ts)。
  2. 什么原因导致的: PR [PR] fix: over-window requests are no longer rejected by local estimation — after folding, always forward; let upstream decid | fix: 超窗请求不再被本地估算拒发——折叠后一律转发,超不超窗让上游自己说 (#7537) #7548(关闭 Preflight: don't reject based on local estimation — after folding, forward unconditionally; if it exceeds the window, le | preflight 不用本地估算拒发:折叠后一律转发,超窗让上游自己说(413 拒发家族总根因) #7537)按 owner 2026-11-22 的裁决移除了所有本地估算 413 拒发,更新了 7 个 preflight 测试文件并删除了 issue3846,但漏掉了 tests/fix-identity-fast-path-preflight.test.ts——这 3 个测试还钉着已移除的 413-veto 行为,所以完整套件红了。是机械疏漏,不是设计缺陷。
  3. 影响范围与严重程度: 仅影响 CI(测试套件红),不影响生产行为——3 个测试测的是已移除的旧行为(413 veto),不是真实缺陷;严重程度 = CI 红,需修复才能合并。
  4. 怎么修复的: 按 PR 作者自己的模式(issue2847/issue4185:413-veto 断言 → forward/upstream-decides 断言)更新这 3 个测试:A2(新鲜证据)保留 200-forward 行为,只把日志断言从 "identity fast path" 改成 Preflight: don't reject based on local estimation — after folding, forward unconditionally; if it exceeds the window, le | preflight 不用本地估算拒发:折叠后一律转发,超窗让上游自己说(413 拒发家族总根因) #7537 的 forward 行;B(旧 origin 证据)和 B2(旧 model 证据)移除 413 veto,断言 payload 被 forward、上游决定。
  5. 是否有回归问题: 无——修复只更新测试断言以匹配新行为,不改任何生产代码;本地验证测试文件 5/5 绿、typecheck 干净。
  6. 是否破坏缓存: 不涉及——测试断言更新,不触碰缓存/重试/增量游标。
  7. 是否改了设计方向: 不涉及——行为是 owner 2026-11-22 已裁决的(无估算拒发),我只是把漏掉的测试文件补齐到 PR 作者自己的模式。
  8. 是否引入了新的配置: 不涉及。

判定: 最终 head 2d65b3cb25f 已推送(无 [ework:ci-held] 标记),触发完整 CI 跑。新 head 的 CI 正在跑,镜像缓存尚旧,不能断言绿——等 CI 结果。

… the body merge (#7537)

The preflight loop guard (byte-hash of an upstream-refused body) fired
before the fit check and the fold walk, so it 413'd two contracts:
#3900's identical retry while the local estimate still fits (the learning
loop needs a second forward) and #987 T3's resend that preflight can fold
under the declared window. The guard is gone — the anti-loop protection
for the truly-doomed payload is the EVIDENCE branch restored in the
deterministic-exhaustion path: nothing more can fold AND the upstream has
already proved the wall (stated/armed overflow) AND the calibrated meter
agrees → local 413, retryable=false (#3461/#496/#767/#857). Estimation-
only exhaustion keeps forwarding (#7537).

The relay size-verdict annotation now marks x-bili-cause/x-bili-retryable
via headers only; the upstream body passes through byte-identical
(#1195 B and request-input-lifetime pin verbatim bodies).

Test re-pins: #2391 eager/loaded tool overflow forwards (measured tier is
an evidence logger, not a judge); #1841 A splits into wall-413 (evidence
survives) + A2 no-wall forward; #4185 resend hits the evidence 413;
#4079/#7537 assert the header-only annotation; ci-shard weights drop the
deleted #3846 pin.
…7537 forward semantics

preflight-zero-fold-calibration: the anonymous-baseline and image-reserve
pins expected the #5000/#4543 measured-doom 413 — exactly the
estimate-refusal family #7537 removes. They now pin the forward contract
(no local refusal, upstream decides; scoped refusal demoted to evidence
input).

preflight-responses-wire: the two unfoldable 4.6MB body/tool pins
expected local 413; they now forward (mock upstream accepts → 200,
exactly one forward each).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Event is stale — no work needed this run.

The reported head 033c679db6 is no longer the branch head. The current head is 6607dfc940a, which includes a follow-up commit 3fe69f59481 ("test: re-pin the zero-fold and responses-wire estimate-doom pins to #7537 forward semantics") that fixes exactly the failing test files:

The 8 failing shards in the event (windows 22 1/2, ubuntu 24 1/2/3, ubuntu 22 1/2/3) were on head 033c679db6; the follow-up commit addresses them.

Live check state: the mirror cache is stale (fetched_at 2026-11-23T01:29:08Z, 8.6 min old at check time) — the current head's CI is running or just completed, but I cannot verify green/red from the cache. No further work from this run.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1282-master.9236576 (rolling master tag).

npm install -g billion-context@0.0.1282-master.9236576  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Nov 23, 2026
…lict, round 7)

Master moved 0b68ade -> 15f06c6 (kernel 0.0.205, +preflight
emergency-digest default-off #7549, +preflight 413 passthrough #7548,
+sessions reattach #7512, +opencode user-fork detection #5511,
+acp-status uncompressed nudge-align #7536, +preflight gate epoch
exception #7558, +413 egress fuse pins #7488, +Korean README #7551,
+many host/test changes).

Conflicts: 3 version-only files (kernel/package.json,
kernel/package-lock.json, root package-lock.json). Resolved to kernel
0.0.206 (merged kernel = superset of master's 0.0.205 + PR #6720/#6762
changes; kernel/src changed vs master => must bump above master's 0.0.205).

Auto-merged clean: kernel/src/compress.ts (PR markers 13x + master
changes), src/stream.ts (PR markers 3x), src/server.ts, master's new
test files, docs.

Local verification: typecheck ✓, build ✓, kernel 1671 pass / 0 fail,
host nudge/receipt 7 pass / 0 fail, kernel-guard ✓ (SRC_CHANGED=2
BUMPED=1 0.0.205->0.0.206), version-guard ✓ (root 0.1.216 untouched),
lock-sync ✓.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant